# 装饰器工厂

def repeat(times):
    """重复执行函数的装饰器工厂"""
    def decorator(func):
        def wrapper(*args, **kwargs):
            results = []
            for i in range(times):
                print(f"🔄 第 {i+1} 次执行")
                results.append(func(*args, **kwargs))
            return results
        return wrapper
    return decorator

# 使用带参数的装饰器
@repeat(3)
def say_hello(name):
    print(f"Hello {name}!")
    return f"Greeted {name}"

result = say_hello("Bob")
print("结果:", result)


from mcp.types import AnyFunction
class FastMCPDemo:
    def __init__(self, name=None, title=None, description=None, annotations=None, structured_output=None):
        self.name = name
        self.title = title
        self.description = description
        self.annotations = annotations
        self.structured_output = structured_output

    def tool(self, name=None, title=None, description=None, annotations=None, structured_output=None):
        # Check if user passed function directly instead of calling decorator
        if callable(name):
            raise TypeError(
                "The @tool decorator was used incorrectly. Did you forget to call it? Use @tool() instead of @tool"
            )

        # 这是一个装饰器工厂，返回真正的装饰器函数
        def decorator(fn: AnyFunction) -> AnyFunction:
            self.add_tool(
                fn,
                name=name,
                title=title,
                description=description,
                annotations=annotations,
                structured_output=structured_output,
            )
            return fn

        return decorator

    def add_tool(self, fn, name, title, description, annotations, structured_output):
        pass


mcpDemo = FastMCPDemo()
@mcpDemo.tool
def annotationMethod():
    pass